﻿using System;
using System.Windows.Forms;
using Styx.Plugins;


namespace Ringo
{
    public partial class Ringo
    {
        partial class RingoLogMeOutConfigForm
        {
            #region Form Code
            private System.ComponentModel.IContainer components = null;
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
            private void InitializeComponent()
            {
                this.EnableLevel = new System.Windows.Forms.CheckBox();
                this.LogoutLevel = new System.Windows.Forms.MaskedTextBox();
                this.EnableHonor = new System.Windows.Forms.CheckBox();
                this.LogoutHonor = new System.Windows.Forms.MaskedTextBox();
                this.LabelHonor = new System.Windows.Forms.Label();
                this.EnableItem = new System.Windows.Forms.CheckBox();
                this.LogoutItemQuantity = new System.Windows.Forms.MaskedTextBox();
                this.LabelItemID = new System.Windows.Forms.Label();
                this.LogoutItemID = new System.Windows.Forms.MaskedTextBox();
                this.EnableTime = new System.Windows.Forms.CheckBox();
                this.LogoutTimeHour = new System.Windows.Forms.MaskedTextBox();
                this.LabelTimeColon = new System.Windows.Forms.Label();
                this.LogoutTimeMinutes = new System.Windows.Forms.MaskedTextBox();
                this.TodayTomorrow = new System.Windows.Forms.ComboBox();
                this.TimeWarning = new System.Windows.Forms.Label();
                this.ButtonExit = new System.Windows.Forms.Button();
                this.EnableHearth = new System.Windows.Forms.CheckBox();
                this.ButtonSave = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // EnableLevel
                // 
                this.EnableLevel.AutoSize = true;
                this.EnableLevel.Location = new System.Drawing.Point(12, 12);
                this.EnableLevel.Name = "EnableLevel";
                this.EnableLevel.Size = new System.Drawing.Size(105, 17);
                this.EnableLevel.TabIndex = 0;
                this.EnableLevel.Text = "Log Out at Level";
                this.EnableLevel.UseVisualStyleBackColor = true;
                // 
                // LogoutLevel
                // 
                this.LogoutLevel.Location = new System.Drawing.Point(135, 10);
                this.LogoutLevel.Mask = "99";
                this.LogoutLevel.Name = "LogoutLevel";
                this.LogoutLevel.Size = new System.Drawing.Size(36, 20);
                this.LogoutLevel.TabIndex = 1;
                this.LogoutLevel.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
                // 
                // EnableHonor
                // 
                this.EnableHonor.AutoSize = true;
                this.EnableHonor.Location = new System.Drawing.Point(12, 36);
                this.EnableHonor.Name = "EnableHonor";
                this.EnableHonor.Size = new System.Drawing.Size(121, 17);
                this.EnableHonor.TabIndex = 2;
                this.EnableHonor.Text = "Logout when I have";
                this.EnableHonor.UseVisualStyleBackColor = true;
                // 
                // LogoutHonor
                // 
                this.LogoutHonor.Location = new System.Drawing.Point(135, 34);
                this.LogoutHonor.Mask = "9999";
                this.LogoutHonor.Name = "LogoutHonor";
                this.LogoutHonor.Size = new System.Drawing.Size(36, 20);
                this.LogoutHonor.TabIndex = 3;
                // 
                // LabelHonor
                // 
                this.LabelHonor.AutoSize = true;
                this.LabelHonor.Location = new System.Drawing.Point(177, 37);
                this.LabelHonor.Name = "LabelHonor";
                this.LabelHonor.Size = new System.Drawing.Size(36, 13);
                this.LabelHonor.TabIndex = 13;
                this.LabelHonor.Text = "Honor";
                // 
                // EnableItem
                // 
                this.EnableItem.AutoSize = true;
                this.EnableItem.Location = new System.Drawing.Point(12, 59);
                this.EnableItem.Name = "EnableItem";
                this.EnableItem.Size = new System.Drawing.Size(121, 17);
                this.EnableItem.TabIndex = 4;
                this.EnableItem.Text = "Logout when I have";
                this.EnableItem.UseVisualStyleBackColor = true;
                // 
                // LogoutItemQuantity
                // 
                this.LogoutItemQuantity.Location = new System.Drawing.Point(135, 57);
                this.LogoutItemQuantity.Mask = "9999";
                this.LogoutItemQuantity.Name = "LogoutItemQuantity";
                this.LogoutItemQuantity.Size = new System.Drawing.Size(36, 20);
                this.LogoutItemQuantity.TabIndex = 5;
                // 
                // LabelItemID
                // 
                this.LabelItemID.AutoSize = true;
                this.LabelItemID.Location = new System.Drawing.Point(177, 60);
                this.LabelItemID.Name = "LabelItemID";
                this.LabelItemID.Size = new System.Drawing.Size(53, 13);
                this.LabelItemID.TabIndex = 15;
                this.LabelItemID.Text = "of Item ID";
                // 
                // LogoutItemID
                // 
                this.LogoutItemID.Location = new System.Drawing.Point(236, 57);
                this.LogoutItemID.Mask = "99999";
                this.LogoutItemID.Name = "LogoutItemID";
                this.LogoutItemID.Size = new System.Drawing.Size(41, 20);
                this.LogoutItemID.TabIndex = 6;
                // 
                // EnableTime
                // 
                this.EnableTime.AutoSize = true;
                this.EnableTime.Location = new System.Drawing.Point(12, 82);
                this.EnableTime.Name = "EnableTime";
                this.EnableTime.Size = new System.Drawing.Size(71, 17);
                this.EnableTime.TabIndex = 7;
                this.EnableTime.Text = "Logout at";
                this.EnableTime.UseVisualStyleBackColor = true;
                // 
                // LogoutTimeHour
                // 
                this.LogoutTimeHour.Location = new System.Drawing.Point(89, 80);
                this.LogoutTimeHour.Mask = "00";
                this.LogoutTimeHour.Name = "LogoutTimeHour";
                this.LogoutTimeHour.Size = new System.Drawing.Size(24, 20);
                this.LogoutTimeHour.TabIndex = 8;
                this.LogoutTimeHour.Text = "23";
                this.LogoutTimeHour.ValidatingType = typeof(System.DateTime);
                // 
                // LabelTimeColon
                // 
                this.LabelTimeColon.AutoSize = true;
                this.LabelTimeColon.Location = new System.Drawing.Point(119, 83);
                this.LabelTimeColon.Name = "LabelTimeColon";
                this.LabelTimeColon.Size = new System.Drawing.Size(10, 13);
                this.LabelTimeColon.TabIndex = 16;
                this.LabelTimeColon.Text = ":";
                // 
                // LogoutTimeMinutes
                // 
                this.LogoutTimeMinutes.Location = new System.Drawing.Point(135, 80);
                this.LogoutTimeMinutes.Mask = "00";
                this.LogoutTimeMinutes.Name = "LogoutTimeMinutes";
                this.LogoutTimeMinutes.Size = new System.Drawing.Size(23, 20);
                this.LogoutTimeMinutes.TabIndex = 9;
                this.LogoutTimeMinutes.Text = "59";
                // 
                // TodayTomorrow
                // 
                this.TodayTomorrow.AutoCompleteCustomSource.AddRange(new string[] {
            "Today",
            "Tomorrow"});
                this.TodayTomorrow.FormattingEnabled = true;
                this.TodayTomorrow.Items.AddRange(new object[] {
            "Today",
            "Tomorrow"});
                this.TodayTomorrow.Location = new System.Drawing.Point(180, 80);
                this.TodayTomorrow.Name = "TodayTomorrow";
                this.TodayTomorrow.Size = new System.Drawing.Size(77, 21);
                this.TodayTomorrow.TabIndex = 10;
                this.TodayTomorrow.Text = "Today";
                // 
                // TimeWarning
                // 
                this.TimeWarning.AutoSize = true;
                this.TimeWarning.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.TimeWarning.ForeColor = System.Drawing.Color.Red;
                this.TimeWarning.Location = new System.Drawing.Point(12, 104);
                this.TimeWarning.Name = "TimeWarning";
                this.TimeWarning.Size = new System.Drawing.Size(265, 24);
                this.TimeWarning.TabIndex = 17;
                this.TimeWarning.Text = "You must use 24 hour time.";
                // 
                // ButtonExit
                // 
                this.ButtonExit.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
                this.ButtonExit.Location = new System.Drawing.Point(12, 135);
                this.ButtonExit.Name = "ButtonExit";
                this.ButtonExit.Size = new System.Drawing.Size(73, 23);
                this.ButtonExit.TabIndex = 12;
                this.ButtonExit.Text = "Exit";
                this.ButtonExit.Click += new System.EventHandler(this.ButtonExit_Click);
                // 
                // EnableHearth
                // 
                this.EnableHearth.AutoSize = true;
                this.EnableHearth.Checked = true;
                this.EnableHearth.CheckState = System.Windows.Forms.CheckState.Checked;
                this.EnableHearth.Location = new System.Drawing.Point(91, 139);
                this.EnableHearth.Name = "EnableHearth";
                this.EnableHearth.Size = new System.Drawing.Size(106, 17);
                this.EnableHearth.TabIndex = 11;
                this.EnableHearth.Text = "Use Hearthstone";
                this.EnableHearth.UseVisualStyleBackColor = true;
                // 
                // ButtonSave
                // 
                this.ButtonSave.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
                this.ButtonSave.Location = new System.Drawing.Point(204, 135);
                this.ButtonSave.Name = "ButtonSave";
                this.ButtonSave.Size = new System.Drawing.Size(73, 23);
                this.ButtonSave.TabIndex = 13;
                this.ButtonSave.Text = "Save";
                this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
                // 
                // RingoLogMeOutConfigForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(288, 170);
                this.Controls.Add(this.EnableLevel);
                this.Controls.Add(this.LogoutLevel);
                this.Controls.Add(this.EnableHonor);
                this.Controls.Add(this.LogoutHonor);
                this.Controls.Add(this.LabelHonor);
                this.Controls.Add(this.EnableItem);
                this.Controls.Add(this.LogoutItemQuantity);
                this.Controls.Add(this.LabelItemID);
                this.Controls.Add(this.LogoutItemID);
                this.Controls.Add(this.EnableTime);
                this.Controls.Add(this.LogoutTimeHour);
                this.Controls.Add(this.LabelTimeColon);
                this.Controls.Add(this.LogoutTimeMinutes);
                this.Controls.Add(this.TodayTomorrow);
                this.Controls.Add(this.TimeWarning);
                this.Controls.Add(this.ButtonExit);
                this.Controls.Add(this.EnableHearth);
                this.Controls.Add(this.ButtonSave);
                this.Name = "RingoLogMeOutConfigForm";
                this.ShowIcon = false;
                this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
                this.Text = "Ringo Log Me Out Configuration";
                this.TopMost = true;
                this.Load += new System.EventHandler(this.Form1_Activated);
                this.Shown += new System.EventHandler(this.Form1_Shown);
                this.ResumeLayout(false);
                this.PerformLayout();

            }
            #endregion
            #region FormDefinitions
            public CheckBox EnableLevel;
            private MaskedTextBox LogoutLevel;
            private CheckBox EnableHonor;
            private MaskedTextBox LogoutHonor;
            private Label LabelHonor;
            private CheckBox EnableItem;
            private MaskedTextBox LogoutItemQuantity;
            private Label LabelItemID;
            private MaskedTextBox LogoutItemID;
            private CheckBox EnableTime;
            private MaskedTextBox LogoutTimeHour;
            private Label LabelTimeColon;
            private MaskedTextBox LogoutTimeMinutes;
            private ComboBox TodayTomorrow;
            private Label TimeWarning;
            private Button ButtonExit;
            public CheckBox EnableHearth;
            private Button ButtonSave;
            #endregion
        }
        public partial class RingoLogMeOutConfigForm : Form
        {
            private DateTime Now = DateTime.Now;
            private DateTime TempTime;
            public RingoLogMeOutConfigForm()
            {
                InitializeComponent();
                this.Activate();
            }
            private void Form1_Shown(object sender, EventArgs e)
            {
                this.Activate();
            }
            private void Form1_Activated(object sender, EventArgs e)
            {
                this.Activate();
            }
            public void ButtonSave_Click(object sender, EventArgs e)
            {
                if (EnableHonor.Checked || EnableItem.Checked || EnableLevel.Checked || EnableTime.Checked)
                {
                    NLog("Ringo Log Me Out activated.");
                    Ringo.EnableLevel = (EnableLevel.Checked && !LogoutLevel.Text.Equals(null));
                    if (EnableLevel.Checked && !LogoutLevel.Text.Equals(null))
                    {
                        Ringo.LogoutLevel = int.Parse(LogoutLevel.Text);
                        NLog("Logout by level active, logging out at level " + LogoutLevel.Text.ToString());
                    }
                    else
                    {
                        DLog("Logout by level inactive.");
                    }
                    Ringo.EnableHonor = (EnableHonor.Checked && !LogoutHonor.Text.Equals(null));
                    if (EnableHonor.Checked && !LogoutHonor.Text.Equals(null))
                    {
                        Ringo.LogoutHonor = int.Parse(LogoutHonor.Text);
                        NLog("Logout by honor active, logging out when I have " + LogoutHonor.Text.ToString() + " honor points.");
                    }
                    else
                    {
                        DLog("Logout by honor inactive");
                    }
                    Ringo.EnableItem = (EnableItem.Checked && !LogoutItemQuantity.Text.Equals(null) && !LogoutItemID.Text.Equals(null));
                    if (EnableItem.Checked && !LogoutItemQuantity.Text.Equals(null) && !LogoutItemID.Text.Equals(null))
                    {
                        Ringo.LogoutItemQuantity = int.Parse(LogoutItemQuantity.Text);
                        Ringo.LogoutItemID = uint.Parse(LogoutItemID.Text);
                        NLog("Logout by item active, logging out when I have " + LogoutItemQuantity.Text.ToString() + " of Item ID " + LogoutItemID.Text.ToString());
                    }
                    else
                    {
                        DLog("Logout by item inactive.");
                    }
                    Ringo.EnableTime = (EnableTime.Checked && !LogoutTimeHour.Text.Equals(null) && !LogoutTimeMinutes.Text.Equals(null));
                    if (EnableTime.Checked && !LogoutTimeHour.Text.Equals(null) && !LogoutTimeMinutes.Text.Equals(null))
                    {
                        int Hours = int.Parse(LogoutTimeHour.Text);
                        int Mins = int.Parse(LogoutTimeMinutes.Text);
                        if (TodayTomorrow.Text.Equals("Tomorrow"))
                        {
                            TempTime = new DateTime(Now.Year, Now.Month, Now.Day, Hours, Mins, 0);
                            LogOutTime = TempTime.AddDays(1);
                        }
                        else if (TodayTomorrow.Text.Equals("Today"))
                        {
                            TempTime = new DateTime(Now.Year, Now.Month, Now.Day, Hours, Mins, 0);
                            LogOutTime = TempTime;
                        }
                        NLog("Logout at time active, logging out at " + LogOutTime.ToString() + ".");
                    }
                    else
                    {
                        DLog("Logout at time inactive.");
                    }
                    Ringo.EnableHearth = EnableHearth.Checked;
                    if (EnableHearth.Checked)
                    {
                        NLog("Will use hearthstone on exit.");
                    }
                    else
                    {
                        NLog("Will not use hearthstone on exit.");
                    }
                }
                else
                {
                    NLog("Ringo Log Me Out is not active, check settings.");
                }
            }
            public void ButtonExit_Click(object sender, EventArgs e)
            {
                Close();
            }
        }
        public class RingoLogMeOut : HBPlugin
        {
            #region HB Required
            private static string SubversionRevision { get { return ("$Rev: 99 $"); } }
            RingoLogMeOutConfigForm ConfigForm = new RingoLogMeOutConfigForm();
            public override string Name { get { return "Ringo Log Me Out"; } }
            public override string Author { get { return "pbettell"; } }
            public override Version Version { get { return new Version(1, 0, 0, 0); } }
            public override string ButtonText { get { return "Setup"; } }
            public override bool WantButton { get { return true; } }
            public override void OnButtonPress()
            {
                ConfigForm.ShowDialog();
            }
            #endregion
            public override void Initialize()
            {
                NLog(Name.ToString() + " - " + SubversionRevision + " initialized.");
            }
            public override void Pulse()
            {
                if (OkayToTakeOverThread())
                {
                    if (EnableLevel)
                    {
                        LogoutLevelCheck();
                    }
                    if (EnableHonor)
                    {
                        LogoutHonorCheck();
                    }
                    if (EnableItem)
                    {
                        LogoutItemCheck();
                    }
                    if (EnableTime)
                    {
                        LogoutTimeCheck();
                    }
                }
            }
        }
    }
}